package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.myapplication.fragment.MineFragment
import com.example.myapplcation.fragment.BaseActivity
import com.example.myapplication.fragment.HomeFragment
import com.example.total.R
import com.example.total.databinding.ActivityMainBinding
import com.example.myapplication.Activity_My

class MainActivity : BaseActivity<ActivityMainBinding>() {
    private val fragments:MutableList<Fragment> = ArrayList()
    private lateinit var memoryCleaner: MemoryCleanerService

    override fun initData() {
        memoryCleaner = MemoryCleanerService()
        fragments.add(HomeFragment())
        fragments.add(MineFragment())
        binding.pager.offscreenPageLimit = fragments.size
        binding.pager.isUserInputEnabled = false
        binding.pager.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount() = fragments.size

            override fun createFragment(position: Int) = fragments[position]
        }
        binding.bottomRg.setOnCheckedChangeListener { _, checkedId ->
            if(checkedId== R.id.home){
                binding.pager.currentItem = 0
                binding.title.text = "主页"
            }else{
                binding.pager.currentItem = 1
                binding.title.text = "我的"
            }
        }
        binding.add.setOnClickListener {
            Intent().apply {
                setClass(this@MainActivity, AddPopularScienceActivity::class.java)
                startActivity(this)
            }
        }
        binding.mine.setOnClickListener {
            Intent().apply {
                setClass(this@MainActivity, Activity_My::class.java)
                startActivity(this)
            }
        }


    }
}